package com.dylearn.domain;

import lombok.Data;

@Data
//@Builder
public class User {
    /**
     * @Author zhangdingyi
     * @Date 2022-08-06 17:18
     * @Content 编程法则第一条 能用 基本类型就用基本类型
     */
    private long id;
    private String userName;
    private String password;
    private String name;
    private int age;
    private String email;

    /**
     * @Author zhangdingyi
     * @Date 2022-08-06 17:09
     * @Content 建造者模式
     */
    public static class Builder {
        private long id = 0;
        private String userName = "";
        private String password = "";
        private String name = "";
        private int age = 0;
        private String email = "";

        public Builder(long id, String userName, String password, String name, int age, String email) {
            this.id = id;
            this.userName = userName;
            this.password = password;
            this.name = name;
            this.age = age;
            this.email = email;
        }

        public Builder() {
        }

        public Builder id(long val) {
            id = val;
            return this;
        }

        public Builder userName(String val) {
            userName = val;
            return this;
        }

        public Builder password(String val) {
            password = val;
            return this;
        }

        public Builder name(String val) {
            name = val;
            return this;
        }

        public Builder age(int val) {
            age = val;
            return this;
        }

        public Builder email(String val) {
            email = val;
            return this;
        }

        public User build() {
            return new User(this);
        }

    }

    private User() {
    }

    private User(Builder builder) {
        this.id = builder.id;
        this.age = builder.age;
        this.email = builder.email;
        this.name = builder.name;
        this.userName = builder.userName;
        this.password = builder.password;
    }

    /**
     * @Author zhangdingyi
     * @Date 2022-08-07 07:36
     * @Content 枚举单例模式
     */
    private enum UserEnum {
        INSTNCE;
        User user;

        private UserEnum() {
            user = new User();
        }

        //这里把在 新建的对象返回出去
        public User getInstnce() {
            return user;
        }
    }

    //对外开放一个 从枚举类获取单例模式的静态接口
    public static User getInstnce() {
        return UserEnum.INSTNCE.getInstnce();
    }


}
